
import numpy as np
import matplotlib.pyplot as plt
from scipy.interpolate import interp1d
#help(interp1d); exit(1)
x = np.linspace(0, 10*np.pi, 20) # 算上首尾，共 20 个点
y = np.sin(x)
f1 = interp1d(x,y,kind='linear') # 线性插值 = 折线图
f2 = interp1d(x,y,kind='cubic') # 三次样条插值
xnew = np.linspace(0, 10*np.pi, 100)
plt.plot( x, y, 'o', xnew, f1(xnew), ':', xnew, f2(xnew), 'k-')
#plt.plot( xnew, np.sin(xnew), "-")
plt.savefig("../../../doc/marp-slides/interpolation.png")
plt.show()

'''
import matplotlib.pyplot as plt
from scipy import interpolate
x = np.arange(0, 10)
y = np.exp(-x / 3.0)
f1 = interpolate.interp1d(x, y, kind='linear')
f2 = interpolate.interp1d(x, y, kind='cubic')
xnew = np.arange(0, 9, 0.1)
plt.plot(x, y, 'o', xnew, f1(xnew), '-', xnew, f2(xnew), ':')
plt.show()
'''